#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->setWindowFlag((Qt::WindowMinMaxButtonsHint),false);//false则隐藏
    //this->setWindowFlags(this->windowFlags()&~Qt::WindowMinMaxButtonsHint);//取反相与，隐藏
    setFixedSize(this->width(),this->height());


    /* 初始化CSInfo数据存储结构体 */
    _ptrCSInfo = new CSInfoStrcutre;
    /* 初始化CSInfo数据读取器_reader */
    _reader = new CSInfoReader();
    /* */
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(flushCSInfoSlot()));
}


MainWindow::~MainWindow()
{
    delete ui;
}


//void MainWindow::on_pushButton_clicked()
//{
//    /* 读取数据 */
//    uint8_t packages[INFOSIZE*3]={0};
//    _reader->readInfoFromSerialport(packages);
//    /* 解析数据 */
//    uint8_t infoArray[INFOSIZE];
//    /* 提取数据包 */
//    CSInfo_GetInfoArrayInpackages(infoArray,packages,INFOSIZE*3);
//    /* 解包 */
//    CSInfo_InfoArray2CSInfoS(infoArray,this->_ptrCSInfo);
//    /* 展示数据 */
//    ui->label_3->setText(QString("%1").arg(_ptrCSInfo->_gp));
//    ui->label_4->setText(QString("%1").arg( _ptrCSInfo->_temp_env));
//    ui->label_5->setText(QString("%1").arg( _ptrCSInfo->_temp_O_MCU));
//}
void MainWindow::flushCSInfoSlot()
{
    /* 读取数据 */
    uint8_t packages[INFOSIZE*3]={0};
    int numHasRead = _reader->readInfoFromSerialport(packages);
    /* 解析数据 */
    uint8_t infoArray[INFOSIZE];
    /* 提取数据包 */
    bool readable = CSInfo_GetInfoArrayInpackages(infoArray,packages,numHasRead);
    /* 解包 */
    if(readable)
        CSInfo_InfoArray2CSInfoS(infoArray,this->_ptrCSInfo);
    /* 展示数据 */
    ui->lab_GP->setText(QString("%1").arg(_ptrCSInfo->_gp));
    ui->lab_Tem_Gas->setText(QString("%1").arg( _ptrCSInfo->_temp_env));
    ui->lab_Tem_Core->setText(QString("%1").arg( _ptrCSInfo->_temp_O_MCU));
    ui->lab_Acc_X->setText(QString("%1").arg( _ptrCSInfo->_acc._acc_X));
    ui->lab_Acc_Y->setText(QString("%1").arg( _ptrCSInfo->_acc._acc_Y));
    ui->lab_Acc_Z->setText(QString("%1").arg( _ptrCSInfo->_acc._acc_Z));
    ui->lab_LL_La->setText(QString("%1").arg( _ptrCSInfo->_ll._latitude));
    ui->lab_LL_Long->setText(QString("%1").arg( _ptrCSInfo->_ll._longitude));

}
